package com.xebia.pomodoro.utils
{
	import com.xebia.pomodoro.enums.P2PMessageType;
	import com.xebia.pomodoro.messages.P2PMessage;
	import com.xebia.pomodoro.messages.PomodoroSyncRequestMessage;
	import com.xebia.pomodoro.messages.RegisterationMessage;
	import com.xebia.pomodoro.model.P2PModel;
	import com.xebia.pomodoro.printer.PrinterUtil;
	import com.xebia.pomodoro.transformer.P2PMessageTransformer;

	import flash.utils.Dictionary;

	public class MessageUtility
	{
		private static var mapTypeToFunction:Dictionary = new Dictionary();

		public static function registerTypeToFunction(type:String, func:Function):void
		{
			mapTypeToFunction[type] = func;
		}

		public function MessageUtility()
		{
		}

		public static function performAction(message:P2PMessage):void
		{
			var func:Function = mapTypeToFunction[message.type];
			if (func != null)
			{
				func.call(null, message);
			}
		}

		public static function executeMessage(recievedMessage:P2PMessage):void
		{
			performAction(recievedMessage);
			PrinterUtil.writeText(recievedMessage);
		}


	}
}
